/*-------------------------------------------------------------------------
 *
 * rewriteheap.h
 *	  堆重写支持函数的声明
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994-5, Regents of the University of California
 *
 * src/include/access/rewriteheap.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef REWRITE_HEAP_H
#define REWRITE_HEAP_H

#include "access/htup.h"
#include "storage/itemptr.h"
#include "storage/relfilenode.h"
#include "utils/relcache.h"

/* 结构定义是rewriteheap.c的私有 */
typedef struct RewriteStateData *RewriteState;

extern RewriteState begin_heap_rewrite(Relation OldHeap, Relation NewHeap,
									   TransactionId OldestXmin, TransactionId FreezeXid,
									   MultiXactId MultiXactCutoff);
extern void end_heap_rewrite(RewriteState state);
extern void rewrite_heap_tuple(RewriteState state, HeapTuple oldTuple,
							   HeapTuple newTuple);
extern bool rewrite_heap_dead_tuple(RewriteState state, HeapTuple oldTuple);

/*
 * 单个逻辑重写映射的磁盘上数据格式。
 */
typedef struct LogicalRewriteMappingData
{
	RelFileNode old_node;
	RelFileNode new_node;
	ItemPointerData old_tid;
	ItemPointerData new_tid;
} LogicalRewriteMappingData;

/* ---
 * 文件名由以下部分组成，用短横线分隔，
 * 组件：
 * 1) 数据库oid或InvalidOid用于共享关系
 * 2) 关系的oid
 * 3) 重写开始时的LSN的高32位
 * 4) 重写开始时的LSN的低32位
 * 5) 我们正在映射的xid
 * 6) 执行映射的xact的xid
 * ---
 */
#define LOGICAL_REWRITE_FORMAT "map-%x-%x-%X_%X-%x-%x"
extern void CheckPointLogicalRewriteHeap(void);

#endif							/* REWRITE_HEAP_H */
